package com.Advance.abstract_;
//提供一个背景来理解模板设计模式的好处
/*
1）有多个类，完成不同的任务job
2）要求能够得到各自完成任务的时间
 */
public class abstract_Template {
    public static void main(String[] args) {
        sub1 sub = new sub1();
        sub.calculate();
        sub2 sub2 = new sub2();
        sub2.calculate();

    }
}
abstract class Template{
    public abstract void job();
    public void calculate() {
        long start = System.currentTimeMillis();
        job();//涉及到动态绑定机制
        long end = System.currentTimeMillis();
        System.out.println("执行时间"+(end - start));
    }
}
class sub1 extends Template{
    @Override
    public void job() {
        int num = 0;
        for (int i = 1; i <= 800000000; i++) {
            num *= i ;
        }
    }
}
class sub2 extends Template{
    @Override
    public void job() {
        int num = 0;
        for (int i = 1; i <= 999999999; i++) {
            num *= i ;
        }
    }
}


